<?php include(BASE_PATH . "/view/layout/admin.phtml"); ?>
    <link rel="stylesheet" type="text/css" href="/css/common/city.css" />
    <script type="text/javascript" src="/js/common/Popt.js"></script>
    <script type="text/javascript" src="/js/common/cityJson.js"></script>
    <script type="text/javascript" src="/js/common/citySet.js"></script>
    <style>
        .sideContent{padding: 60px;}
        .header{height: 40px;background: #F2F2F2;padding-left: 20px;padding-top: 11px;}
        .btn-cont{text-align: right;margin-bottom: 20px;}
        ._citys{width: 397px;}
        .add-model{
            position: absolute;
            width: 100%;
            height: 100%;
            top: 0;
            display: none;
        }
        .add-zhe{
            position: absolute;
            background: rgba(0,0,0,0.3);
            height: 100%;
            width: 100%;
        }
        .add-input{
            position: absolute;
            left: 50%;
            top:10%;
            width: 520px;
            height: 300px;
            margin-left: -260px;
            z-index: 99;
            background: white;
            padding:20px;
            border-radius: 5px;
        }

        .input-group{
            margin: 40px auto;
        }
        .input-group input{
            border-radius: 3px;
            border: 1px solid #bfbfbf;
            color: gray;
            height: 32px;
            width: 320px;
            padding-left: 20px;
            position: relative;
            z-index: 2;
            background: rgba(255, 255, 255, 0);
        }
        .input-group input:hover{
            border: 1px solid;
        }
        .sfi{
            position: absolute;
            right: 10px;
            top: 3px;
            letter-spacing: 2px;
        }
        #textCity{
            cursor: pointer;
        }
        .add-btn-cont{
            text-align: center;
        }
        .add-btn-cont .btn{width: 75px;}
        .w-1{width: 5%;}
        .w-2{width: 20%;}
        .w-3{width: 30%;}
        .w-4{width: 10%;}
        .table th,td{text-align: center;}
        .pointer{cursor: pointer;}
    </style>
    <div class="header">
        <span>组织管理</span>
        <span>/</span>
        <span>站点管理</span>
    </div>
    <div class="sideContent">
        <div class="btn-cont">
            <button id="addSideBtn" type="button" class="btn btn-default">添加站点</button>
        </div>
        <table class="table table-bordered table-striped table-hover">
            <thead>
            <tr>
                <th class="w-1">编号</th>
                <th class="w-2">所在城市</th>
                <th class="w-2">站点名称</th>
                <th class="w-2">创建时间</th>
                <th class="w-2">操作人</th>
                <th class="w-4">操作</th>
            </tr>
            </thead>
            <tbody>
            <?php  foreach ($data['result'] as $rows){?>
                <tr>
                    <td><?php echo $rows['id']?></td>
                    <td><?php echo $rows['city']?></td>
                    <td><?php echo $rows['adress']?></td>
                    <td><?php echo $rows['insert_dt']?></td>
                    <td><?php echo $rows['scope']?></td>
                    <td>
                        <a class="pointer" did="<?php echo $rows['id']?>">修改</a>
                        <span>&nbsp;</span>
                        <a class="delete pointer" did="<?php echo $rows['id']?>">删除</a>
                    </td>
                </tr>
            <?php }?>
            </tbody>
        </table>
        <nav style="text-align: center;">
            <?php echo $data['page'];?>
        </nav>
    </div>
    <div class="add-model">
        <div class="add-zhe"></div>
        <div class="add-input">
            <div class="input-group">
                <span class="mr20">所在城市:</span>
                <input id="textCity" type="text" placeholder="请选择所在城市" readonly="readonly">
                <span class="sfi">...</span>
            </div>
            <div class="input-group">
                <span class="mr20">站点名称:</span>
                <input id="siteName" type="text" placeholder="请填写站点名称" maxlength="50">
            </div>
            <div class="add-btn-cont">
                <button id="siteSave" type="button" class="btn btn-primary mr50">确认</button>
                <button id="cancel" type="button" class="btn btn-default">取消</button>
            </div>
        </div>
    </div>
    <script>
        $(function(){
            $("#textCity").click(function (e) {
                SelCity(this,e);
            });
            Side.init();
        })

        var Side = {
            init:function(){
                this.addEvent();
                this.SaveEvent();
                this.delEvent();
            },
            addEvent:function(){
                $("#addSideBtn").click(function(){
                    $(".add-model").show();
                })
                $("#cancel").click(function(){
                    $(".add-model").hide();
                })
            },
            SaveEvent:function () {
                $("#siteSave").click(function () {
                    var siteCity = $("#textCity").val();
                    var siteName = $("#siteName").val();
                    $.ajax({
                        type:"POST",
                        url:"/application/site/addSite",
                        dataType:"JSON",
                        data:{"siteCity":siteCity,"siteName":siteName},
                        success:function (ret) {
                            if(ret.result == 0){
                                var callback =function(){
                                    window.location.reload();
                                }
                                popupalert("注册成功！","message",callback);
                            }
                        },
                        error:function () {
                            var callback =function(){
                                window.location.reload();
                            }
                            popupalert("注册失败！","error",callback);
                        }
                    })
                })
            },
            delEvent:function () {
                $(".delete").click(function () {
                    var id = $(this).attr("did");
                    $.ajax({
                        type:"POST",
                        url:"/application/site/delete",
                        dataType:"JSON",
                        data:{"id":id},
                        success:function (ret) {
                            if(ret.result == 0){
                                var callback =function(){
                                    window.location.reload();
                                }
                                popupalert("删除成功！","message",callback);
                            }
                        },
                        error:function () {
                            var callback =function(){
                                window.location.reload();
                            }
                            popupalert("删除失败！","error",callback);
                        }
                    })
                })
            }

        }
    </script>
<?php include(BASE_PATH . "/view/layout/adminFooter.phtml"); ?>